Add gtk_container_child_notify
authorMatthias Clasen <mclasen@redhat.com>
Sat, 16 Apr 2011 17:57:05 +0000 (13:57 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 6 May 2011 18:29:14 +0000 (14:29 -0400)
This is a variant of gtk_widget_child_notify() that takes an
explicit container, instead of relying on widget->parent to
be the correct container to use.

gtk/gtkcontainer.c
gtk/gtkcontainer.h
gtk/gtkwidget.c

index 2a1438a2ee8eef4495d90c430357dd1bf68a5e7e..4b6c584078828ec4c7b9604ac11092d5dec4dd2a 100644 (file)
@@ -764,6 +764,68 @@ gtk_container_child_type (GtkContainer *container)
 }
 
 /* --- GtkContainer child property mechanism --- */
+
+/**
+ * gtk_container_child_notify:
+ * @container: the #GtkContainer
+ * @widget: the child widget
+ * @child_property: the name of a chld property installed on
+ *     the class of @container
+ *
+ * Emits a #GtkWidget::child-notify signal for the
+ * <link linkend="child-properties">child property</link>
+ * @child_property on widget.
+ *
+ * This is an analogue of g_object_notify() for child properties.
+ *
+ * Also see gtk_widget_child_notify().
+ *
+ * Since: 3.2
+ */
+void
+gtk_container_child_notify (GtkContainer *container,
+                            GtkWidget    *widget,
+                            const gchar  *child_property)
+{
+  GObject *obj;
+  GParamSpec *pspec;
+
+  g_return_if_fail (GTK_IS_CONTAINER (container));
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (child_property != NULL);
+
+  obj = G_OBJECT (widget);
+
+  if (obj->ref_count == 0)
+    return;
+
+  g_object_ref (obj);
+
+  pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
+                                    child_property,
+                                    G_OBJECT_TYPE (container),
+                                    TRUE);
+
+  if (pspec == NULL)
+    {
+      g_warning ("%s: container class `%s' has no child property named `%s'",
+                 G_STRLOC,
+                 G_OBJECT_TYPE_NAME (container),
+                 child_property);
+    }
+  else
+    {
+      GObjectNotifyQueue *nqueue;
+
+      nqueue = g_object_notify_queue_freeze (obj, _gtk_widget_child_property_notify_context);
+
+      g_object_notify_queue_add (obj, nqueue, pspec);
+      g_object_notify_queue_thaw (obj, nqueue);
+    }
+
+  g_object_unref (obj);
+}
+
 static inline void
 container_get_child_property (GtkContainer *container,
                               GtkWidget    *child,
index b21e2d827badb9cb293d2d4f46a2fae38f53ca6e..a19d90f9d1bf58b9f5f09545d176d9aa8b968c28 100644 (file)
@@ -195,7 +195,11 @@ void            gtk_container_child_set_property           (GtkContainer      *container,
 void        gtk_container_child_get_property           (GtkContainer      *container,
                                                         GtkWidget         *child,
                                                         const gchar       *property_name,
-                                                        GValue            *value);
+                                                        GValue            *value);
+
+void gtk_container_child_notify (GtkContainer *container,
+                                 GtkWidget    *child,
+                                 const gchar  *property_name);
 
 /**
  * GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID:
index 575c9594c7ee1650c75f7a6ea712d0a0ee89421d..db2b824e6e058743c94bc8c5f627746c1146c698 100644 (file)
@@ -3587,37 +3587,17 @@ gtk_widget_freeze_child_notify (GtkWidget *widget)
  * on @widget.
  *
  * This is the analogue of g_object_notify() for child properties.
- **/
+ *
+ * Also see gtk_container_child_notify().
+ */
 void
 gtk_widget_child_notify (GtkWidget    *widget,
-                        const gchar  *child_property)
+                         const gchar  *child_property)
 {
-  GtkWidgetPrivate *priv = widget->priv;
-  GParamSpec *pspec;
-
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (child_property != NULL);
-  if (!G_OBJECT (widget)->ref_count || !priv->parent)
+  if (widget->priv->parent == NULL)
     return;
 
-  g_object_ref (widget);
-  pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
-                                   child_property,
-                                   G_OBJECT_TYPE (priv->parent),
-                                   TRUE);
-  if (!pspec)
-    g_warning ("%s: container class `%s' has no child property named `%s'",
-              G_STRLOC,
-              G_OBJECT_TYPE_NAME (priv->parent),
-              child_property);
-  else
-    {
-      GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
-
-      g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
-      g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
-    }
-  g_object_unref (widget);
+  gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
 }
 
 /**